home *** CD-ROM | disk | FTP | other *** search
- #include <Palettes.h>
- #include <GestaltEqu.h>
- #include <Icons.h>
- #include <A4Stuff.h>
- #include "DS Additions.h"
- #include "Drag.h"
- #include <Components.h>
- #include <QuickTimeComponents.h>
- #include "Offscreen.h"
-
-
- #define ScreenDepth(gdh) ((*((*gdh)->gdPMap))->pixelSize)
-
- struct {
- Component videoComponent;
- ComponentInstance videoInstance;
- };
-
- pascal long main( DSAdditionParamBlockPtr params)
- {
- long result = 0;
- Rect localRect;
- Point mousePoint;
- OSErr theErr;
- RGBColor redColor, blueColor;
- long oldA4 = SetCurrentA4();
- Component comp;
- ComponentInstance ci;
- ComponentDescription looking;
- VideoDigitizerComponent vci;
- GrafPtr savePort;
- VideoDigitizerError error;
- SGChannel videoChannel;
- GDHandle gdh;
- Rect maxRect;
- WindowOffscreen *offscreen;
-
- switch(params->dsMessage) {
- /*
- Given a draw message, draw what we need into the
- provided rectangle
- */
- case kMsgInitAddition:
- params->dsRefCon = 0;
- looking.componentType = videoDigitizerComponentType;
- looking.componentSubType = 0;
- looking.componentManufacturer = 0;
- looking.componentFlags = 0;
- looking.componentFlagsMask = 0;
- comp = FindNextComponent(0, &looking);
- if(comp) {
- vci = (VideoDigitizerComponent)OpenComponent(comp);
- params->dsRefCon = (long)vci;
- }
- result = (params->dsRefCon == 0);
- break;
-
- case kMsgCloseAddition:
- if(params->dsRefCon != nil) {
- CloseComponent((VideoDigitizerComponent)params->dsRefCon);
- }
- break;
-
- case kMsgDrawHilite:
- case kMsgDraw:
- localRect = params->dsLocalRect;
- GetPort(&savePort);
- error = 0;
-
- offscreen = nil;
- if(params->dsRefCon != nil) {
- GetGWorld((CGrafPtr *)&savePort, &gdh);
- if(savePort == params->dsWindow) {
- gdh = nil;
- }
- if((savePort != params->dsWindow) && gdh) {
- error = VDGetMaxSrcRect((VideoDigitizerComponent)params->dsRefCon, 0, &maxRect);
- if(maxRect.right - maxRect.left < localRect.right - localRect.left){
- localRect.right = localRect.left + (maxRect.right - maxRect.left);
- }
- if(maxRect.bottom - maxRect.top < localRect.bottom - localRect.top){
- localRect.bottom = localRect.top + (maxRect.bottom - maxRect.top);
- }
- error = VDSetPlayThruDestination((VideoDigitizerComponent)params->dsRefCon, (*gdh)->gdPMap, &localRect, nil, nil);
- if(!error) {
- error = VDSetDigitizerRect((VideoDigitizerComponent)params->dsRefCon, &localRect);
- if(!error) {
- error = VDGrabOneFrame((VideoDigitizerComponent)params->dsRefCon);
- }
- }
- }
- else{
- error = -2;
- }
- if(offscreen) {
- DrawOnscreen(offscreen);
- }
- }
- else {
- error = -1;
- }
- if(error) {
- PlotIconID(¶ms->dsIconRect, atHorizontalCenter + atBottom, ttDisabled, 200);
- }
- params->dsNextDrawTime = TickCount() + 5; //Draw again in 5 seconds
- break;
-
- /*
- Given a hit message, do whatever we do when we are hit
- */
- case kMsgHit:
- localRect = params->dsLocalRect;
- GetMouse(&mousePoint);
-
- //Make sure that the user actually let go inside the rect
- //before doing our thing.
- while(StillDown() && PtInRect(mousePoint, &localRect)) {
- GetMouse(&mousePoint);
- }
-
- if(!StillDown()) {
- SysBeep(10); //Perhaps I should copy the image to the clipboard? Maybe later.
- }
- break;
-
- /*
- Given a drop message, pull the files out of the
- DragReference then do what you want with them.
- */
- case kMsgDropOccurred:
- {
- unsigned short items, index;
-
- CountDragItems(params->dsDragReference, &items);
- for (index = 1; index <= items; index++) {
- SysBeep(10);
- }
- }
- break;
-
-
- }
-
- SetA4(oldA4);
- return result;
- }
-